<template>
    <div class="seller">
        <div class="seller-content">
            <div class="overview">
                <h1 class="title">{{seller.name}}</h1>
                <div class="desc">
                    <div class="star-wrap">
                        <div class="star">★★★★★</div>
                        <div class="star2" :style="{width:sellerstar}">★★★★★</div>
                    </div>
                    <span class="ratingC">({{seller.ratingCount}})</span>
                    <span class="sellC">月售{{seller.sellCount}}单</span>
                </div>
                <ul class="remark">
                    <li class="block">
                        <h2>起送价</h2>
                        <div class="content">
                            <span class="stress">{{seller.minPrice}}<span>元</span></span>
                        </div>
                    </li>
                    <li class="block">
                        <h2>商家配送</h2>
                        <div class="content">
                            <span class="stress">{{seller.deliveryPrice}}<span>元</span></span>
                        </div>
                    </li>
                    <li class="block">
                        <h2>平均配送时间</h2>
                        <div class="content">
                            <span class="stress">{{seller.deliveryTime}}<span>分钟</span></span>
                        </div>
                    </li>
                </ul>
                <div class="collect">
                  <span class="icon" :class="{'active':favorite}" @click="show">❤</span>
                  <span class="text">{{favor}}</span>
                </div>
                <div class="split"></div>
            </div>
            <div class="annouce">
                <div class="active">公告与活动</div>
                <div class="text">{{seller.bulletin}}</div>
            </div>
            <ul class="cheap">
                <li class="item-wrap" v-for="(item) in seller.supports" :key="item.type">
                    <div class="icon" :class="classMap[item.type]"></div>
                    <div class="desc">{{item.description}}</div>
                </li>
            </ul>
            <div class="split"></div>
            <div class="store">
                <div class="title">商家实景</div>
                <div class="pics-wrap">
                    <ul class="pics">
                        <li class="picWrap" v-for="(item,i) in seller.pics" :key="item[i]">
                            <img :src="item" alt="">
                        </li>
                    </ul>
                </div>
            </div>
            <div class="split"></div>
            <div class="infos">
              <div class="title">商家信息</div>
              <ul class="info">
                <li class="item-wrap" v-for="item in seller.infos" :key="item">
                  <div class="text">
                    {{item}}
                  </div>
                </li>
              </ul>
            </div>
        </div>
    </div>
</template>

<script>
import shopcart from '../shopcart/shopcart.vue'
import BScroll from 'better-scroll'
export default {
  props: ['seller'],
  created() {
    this.classMap = ['decrease', 'discount', 'special', 'invoice', 'guarantee']
  },
  mounted() {
    this.scroll = new BScroll(document.querySelector('.seller'), {
      click: true
    })
    //   let picWidth = 120
    //   let margin = 6
    //   let width = (picWidth + margin) * this.seller.pics.length - margin
    //   document.querySelector('.pics').style.width = width + 'px'
    this.$nextTick(() => {
      //   console.log(2)
      //   this.picScroll = new BScroll(document.querySelector('.pics-wrap'), {
      //     click: true,
      //     scrollX: true,
      //     eventPassthrough: 'vertical'
      this.initX()
    })
    // this.initX()
    // })
  },
  watch: {
    seller() {
      console.log(5)
      this.$nextTick(() => {
        this.initX()
      })
    }
  },
  methods: {
    initX() {
      // console.log(1)
      let widthX = 120
      let margin = 6
      let width = (widthX + margin) * this.seller.pics.length - margin
      document.querySelector('.pics').style.width = width + 'px'
      this.$nextTick(() => {
        if (!this.xScroll) {
          // console.log(2)
          this.xScroll = new BScroll(document.querySelector('.pics-wrap'), {
            scrollX: true,
            eventPassthrough: 'vertical'
          })
        } else {
          this.xScroll.refresh()
          console.log(3)
        }
      })
    },
    show() {
      this.favorite = !this.favorite
      console.log(this.favorite)
    }
  },
  components: {
    shopcart
  },
  data () {
    return {
      favorite: false
    }
  },
  computed: {
    favor() {
      return this.favorite === true ? '已收藏' : '收藏'
    },
    sellerstar() {
      return this.seller.score * 20 + '%'
    }
  }
}
</script>

<style lang="scss">
@import "../../common/scss/basees.scss";
@import "../../common/scss/_mixins.scss";
.seller {
  padding: 18px;
  position: absolute;
  top: 174px;
  bottom: 0;
  left: 0;
  width: 100%;
  overflow: hidden;
  .seller-content {
    .overview {
      .title {
        font-size: 14px;
        color: rgb(7, 17, 27);
        line-height: 14px;
        margin-bottom: 8px;
      }
      .desc {
        display: flex;
        align-items: center;
        height: 18px;
        margin-bottom: 18px;
        .star-wrap {
          width: 65.28px;
          position: relative;
          margin-right: 8px;
          .star {
            color: rgb(147, 153, 159);
          }
          .star2 {
            color: orange;
            position: absolute;
            top: 0;
            left: 0;
            overflow: hidden;
          }
        }
        .ratingC {
          font-size: 10px;
          color: rgb(77, 85, 93);
          margin-right: 12px;
        }
        .sellC {
          font-size: 10px;
          color: rgb(77, 85, 93);
        }
      }
      .remark {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 18px;
        border-top: 1px solid rgba(7, 17, 27, 0.1);
        padding: 0 20px;
        .block {
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          h2 {
            margin: 18px 0 4px 0;
            font-size: 10px;
            color: rgb(147, 153, 159);
          }
          .content {
            .stress {
              font-size: 24px;
              font-weight: 200;
              color: rgb(7, 17, 27);
              span {
                font-size: 10px;
              }
            }
          }
        }
      }
      .collect {
        position: absolute;
        right: 18px;
        top: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        width: 35px;
        height: 35px;
        .icon {
          color: rgb(147, 153, 159);
          &.active {
            color: rgb(240, 20, 20);
          }
        }
        .text {
          font-size: 10px;
          color: rgb(77, 85, 93);
        }
      }
    }
    .annouce {
      border-bottom: 1px solid rgba(7, 17, 27, 0.1);
      .active {
        font-size: 14px;
        color: rgb(7, 17, 27);
        line-height: 14px;
        margin: 18px 0 8px 0;
      }
      .text {
        font-size: 12px;
        font-weight: 200;
        color: rgb(240, 20, 20);
        line-height: 24px;
        padding: 0 12px;
        margin-bottom: 16px;
      }
    }
    .split {
      width: 100%;
      height: 18px;
      border-top: 1px solid #ccc;
      border-bottom: 1px solid #ccc;
      background-color: #d9c9c926;
    }
    .cheap {
      .item-wrap {
        padding: 16px 12px;
        display: flex;
        align-items: center;
        border-bottom: 1px solid rgba(7, 17, 27, 0.1);
        .icon {
          width: 16px;
          height: 16px;
          background-color: red;
          margin-right: 6px;
          &.decrease {
            @include bg-image("decrease_2");
          }
          &.discount {
            @include bg-image("discount_2");
          }
          &.guarantee {
            @include bg-image("guarantee_2");
          }
          &.invoice {
            @include bg-image("invoice_2");
          }
          &.special {
            @include bg-image("special_2");
          }
        }
        .desc {
          font-size: 12px;
          font-weight: 200;
          color: rgb(7, 17, 27);
        }
      }
      .item-wrap:last-of-type {
        border-bottom: none;
      }
    }
    .store {
      padding-left: 18px;
      margin-bottom: 18px;
      .title {
        font-size: 14px;
        color: rgb(7, 17, 27);
        font-weight: 700;
        margin: 18px 0 12px 0;
      }
      .pics-wrap {
        width: 100%;
        white-space: nowrap;
        overflow: hidden;
        .picWrap {
          display: flex;
          align-items: center;
          margin-right: 6px;
          width: 120px;
          height: 90px;
          display: inline-block;
          font-size: 0;
          img {
            width: 100%;
            height: 100%;
          }
        }
      }
    }
    .infos {
      padding-bottom: 16px;
      .title {
        font-size: 14px;
        line-height: 14px;
        color: rgb(7, 17, 27);
        font-weight: 700;
        margin-top: 14px;
      }
      .info {
        padding-left: 12px;
        .item-wrap {
          margin: 16px 0 16px 0;
          border-top: 1px solid rgba(7, 17, 27, 0.1);
          .text {
            font-size: 12px;
            font-weight: 200;
            color: rgb(7, 17, 27);
            line-height: 16px;
          }
        }
      }
    }
  }
}
</style>
